home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pascala.zip / ACK.PAS next >
Pascal/Delphi Source File  |  1991-05-05  |  2KB  |  65 lines

  1. (***************************************)
  2. (* Alejo Alamilo                       *)
  3. (* COSC 055                            *)
  4. (* Spring 1990                         *)
  5. (* Acker Program                       *)
  6. (***************************************)
  7.  
  8.  
  9. Program Ackermann (INPUT,OUTPUT);
  10.  
  11.  
  12. (*************************************************************)
  13. (* The Ackerman function is defined recursively.             *)
  14. (*  It is a function of two integer variables defined below: *)
  15. (*  Ack(M,N) = N+1 if M=0                                    *)
  16. (*  Ack(M,N) = Ack(M-1,1) if N=0                             *)
  17. (*  Ack(M,N) = Ack(M-1,Ack(M,N-1)) otherwise                 *)
  18. (*************************************************************)
  19.  
  20. VAR
  21.   M,N,I,J:INTEGER;
  22.  
  23. FUNCTION Acker(M,N:INTEGER):INTEGER;
  24.  BEGIN (* Ackerman function *)
  25.   IF M = 0 THEN
  26.   Acker:= N + 1
  27.   ELSE
  28.    IF N = 0 THEN
  29.    Acker := Acker(M-1,1)
  30.    ELSE
  31.     Acker := Acker (M-1,Acker (M,N-1))
  32.  END;  (* Ackerman function *)
  33.  
  34. BEGIN (* MAIN *)
  35.   I := 0;
  36.   J := 0;
  37.  
  38.   Write (' Enter in M value:  ');
  39.   Readln (M);
  40.   Write (' Enter in N value:  ');
  41.   Readln (N);
  42.   Writeln;
  43.   Writeln;
  44.   Writeln (' The Ackermann value for ',M:0,' and ',N:0,':');
  45.   Writeln (' N ');
  46.   Writeln ('  ┌─────────────────────────────────┐');
  47.   Writeln ('  │0  1   2   3   4   5   6   7   8 │');
  48.   Writeln ('M\└─────────────────────────────────┘');
  49.   While I <= N Do
  50.   BEGIN
  51.   Write (I:0,' │');
  52.   While (J <= 8) AND NOT ((J = M + 1) AND (I = N)) Do
  53.  
  54.   BEGIN
  55.     Write (Acker (I,J): 4);
  56.     J := J + 1;
  57.     END;
  58.  
  59.   Writeln;
  60.   J := 0;
  61.   I := I +1;
  62.   END;
  63. END.
  64. End;
  65.